﻿@model IEnumerable<Keleyi.Com.Model.MessageInfo>
@{
    ViewBag.Title = "留言板后台";
}
<h2>后台管理 留言列表</h2>
@foreach (var item in Model) {
<div style="border:1px solid black;margin-top:15px;">
   时间：  @item.kAddtime 标题：  @item.kTitle
<hr />
    内容：  @item.kContent
<hr />
    是否公开：<span id="keleyi@{@item.kID}">@item.kIsshow</span> 
    操作：<a href="javascript:KeleyiTurnIsShow('@item.kID ','True')">公开</a>
    <a href="javascript:KeleyiTurnIsShow('@item.kID ','False')">隐藏</a>
</div>
}
@using (Html.BeginForm("TurnIsShow", "MessageAdmin", FormMethod.Post, new { @class = "keleyi", @id = "IsshowForm" }))
{
    @Html.Hidden("kid","8")
    @Html.Hidden("kisshow", "false")
}
<script src="/Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
var myid, myisshow;
$(document).ready(function () {
    $("#IsshowForm").submit(function (event) {
        event.preventDefault();
        keleyiAjax(this, update_sessions, "html");
    });
})
function KeleyiTurnIsShow(kid, kisshow) {
    $("#kid").val(kid);
    $("#kisshow").val(kisshow);
    myid = kid;
    myisshow = kisshow;
    $("#IsshowForm").submit();
}
function keleyiAjax(form, callback, format) {
    $.ajax({
        url: form.action,
        type: form.method,
        dataType: format,
        data: $(form).serialize(),
        success: callback ,
        error: function(err) {
        alert('出错了' + err);
    }
    });
}
function update_sessions(result) {
    var theSpan = $(('#keleyi' + myid));
    theSpan.text("" + myisshow);
}
</script>